package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

import ru.st.selenium.model.Film;

public class MyCollectionPage extends InternalPage{
	
	public MyCollectionPage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(id = "q")
	private WebElement searchField;
	
	@FindBy(css = ".title")
	private WebElement movieTitle;
	
	public MyCollectionPage ensurePageLoaded() {
 		super.ensurePageLoaded();
 		wait.until(presenceOfElementLocated(By.id("q")));
 		return this;
 	}
	
	/////////////////// search ///////////////////////////////
	public MyCollectionPage setSearchField(String text) {
		searchField.clear();
		searchField.sendKeys(text+Keys.RETURN);
		return this;
	}
	
	public MyCollectionPage clickSearchField() {
		searchField.click();
		return pages.myCollectionPage;
	}
	//////////////////////////////////////////////////////////
	
	public MyCollectionPage clickMovieTitle(String title){
		wait.until(presenceOfElementLocated(By.xpath(".//*[text()='"+title+"']/.."))).click();
		return pages.myCollectionPage;
	}
	
}
